In [1]:
import re
from glob import glob
import inspect

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline

from bokeh.io import output_notebook
from bokeh.plotting import show
output_notebook()

from electroninserts import (
    parameterise_single_insert, display_parameterisation,
    convert2_ratio_perim_area, interactive, fallback_scatter,
    spline_model_with_deformability)


Loading BokehJS ...

In [2]:
# !pip install --upgrade version_information
# %load_ext version_information
# %version_information electroninserts, re, numpy, pandas, matplotlib, bokeh, version_information


Requirement already up-to-date: version_information in c:\users\sbiggs\appdata\local\continuum\anaconda3\envs\electroninserts\lib\site-packages
Out[2]:
SoftwareVersion
Python3.5.2 64bit [MSC v.1900 64 bit (AMD64)]
IPython5.0.0
OSWindows 7 6.1.7601 SP1
electroninserts0.1.0
re2.2.1
numpy1.11.1
pandas0.18.1
matplotlib1.5.1
bokeh0.11.1
version_information1.0.3
Fri Aug 05 15:25:36 2016 AUS Eastern Standard Time

Define and parameterise insert


In [3]:
energy = 6
applicator = 10
ssd = 100

x = [0.99, -0.14, -1.0, -1.73, -2.56, -3.17, -3.49, -3.57, -3.17, -2.52, -1.76,
    -1.04, -0.17, 0.77, 1.63, 2.36, 2.79, 2.91, 3.04, 3.22, 3.34, 3.37, 3.08, 2.54,
    1.88, 1.02, 0.99]
y = [5.05, 4.98, 4.42, 3.24, 1.68, 0.6, -0.64, -1.48, -2.38, -3.77, -4.81,
    -5.26, -5.51, -5.58, -5.23, -4.64, -3.77, -2.77, -1.68, -0.29, 1.23, 2.68, 3.8,
    4.6, 5.01, 5.08, 5.05]

width, length, poi = parameterise_single_insert(x, y)
print("Width = {0:0.2f} cm\nLength = {1:0.2f} cm".format(width, length))

display_parameterisation(x, y, width, length, poi)


Width = 6.53 cm
Length = 10.99 cm

Load model data


In [4]:
data_filelist = glob('*_data.csv')
assert len(data_filelist) <= 1, "There appears to be more than 1 data.csv file, please delete the old version(s)"
assert len(data_filelist) == 1, "I need at least one data file"
data_filename = data_filelist[0]
data = pd.read_csv(data_filename)

Only use the data for the specified energy, applicator, and ssd


In [5]:
reference = (
    (data['Energy (MeV)'] == energy) &
    (data['Applicator (cm)'] == applicator) &
    (data['SSD (cm)'] == ssd)
)

input_dataframe = data[reference]
label = np.array(input_dataframe['Label']).astype(str)
width_data = np.array(
    input_dataframe['Width (cm @ 100SSD)']).astype(float)
length_data = np.array(
    input_dataframe['Length (cm @ 100SSD)']).astype(float)
factor_data = np.array(
    input_dataframe['Insert factor (dose insert / dose open)']).astype(float)

input_dataframe


Out[5]:
Label Width (cm @ 100SSD) Length (cm @ 100SSD) Energy (MeV) Applicator (cm) SSD (cm) Insert factor (dose insert / dose open)
75 P62 3.99 6.51 6 10 100 0.9643
76 P50 4.10 5.99 6 10 100 0.9662
77 Simon 5cm_6MeV 4.99 5.00 6 10 100 0.9766
78 Simon 5.3x12.5cm_6MeV 5.26 12.45 6 10 100 0.9960
79 P7 5.69 7.58 6 10 100 0.9950
80 Appears to be a standard 6cm P5_1 6.00 6.00 6 10 100 0.9887
81 P9_1 5.79 7.20 6 10 100 0.9852
82 Simon 6.1cm_6MeV 6.09 6.10 6 10 100 0.9901
83 P24 6.47 8.25 6 10 100 0.9950
84 Simon 6.7x12cm_6MeV 6.76 12.00 6 10 100 0.9980
85 Simon 7.25cm_6MeV 7.23 7.26 6 10 100 1.0070
86 P35_2 7.43 10.30 6 10 100 0.9940
87 Simon 8.3cm_6MeV 8.28 8.30 6 10 100 1.0060
88 P6 8.50 10.73 6 10 100 0.9990
89 Simon 8.5x10.9cm_6MeV 8.50 10.85 6 10 100 1.0030
90 Simon 9.5cm_6MeV 9.49 9.50 6 10 100 1.0050

Calculate the factor


In [6]:
number_of_data = len(input_dataframe)    

if number_of_data >= 8:
    ratio_perim_area_data = convert2_ratio_perim_area(width_data, length_data)

    ratio_perim_area = convert2_ratio_perim_area(width, length)
    factor = float(spline_model_with_deformability(width, ratio_perim_area,
        width_data, ratio_perim_area_data, factor_data))
else: 
    factor = np.nan

print("Width = {0:0.2f} cm\nLength = {1:0.2f} cm\nFactor = {2:0.4f}".format(
        width, length, factor))


Width = 6.53 cm
Length = 10.99 cm
Factor = 0.9969

Display the model


In [7]:
if number_of_data >= 8:
    ratio_perim_area_data = convert2_ratio_perim_area(width_data, length_data)

    figure = interactive(
        width_data, length_data, ratio_perim_area_data, factor_data, label)
else:
    figure = fallback_scatter(width_data, length_data, factor_data, label) 
    
show(figure)


Out[7]:

<Bokeh Notebook handle for In[7]>

Copyright © 2016 Simon Biggs

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.